const nunjucks = require('nunjucks');
const { VIEW_ROOT } = require('./config/config');
const BuildController = require('./controller/BuildController')
const controller = new BuildController();

nunjucks.configure(VIEW_ROOT, {
    autoescape: false,
    watch: true,
});

const cmdName = process.argv.slice(2).toString().trim();
(async () => {
    try {
        switch (cmdName) {
            case '--index':
                controller.index();
                break;
            case '--list':
                controller.list();
                break;
            case '--new':
                controller.new();
                break;
            case '--recommand':
                controller.recommand();
                break;
            case '--search':
                controller.search();
                break;
            case '--detail':
                controller.detail();
                break;
            default:
                await controller.buildCache();
                await controller.index();
                await controller.list();
                await controller.tag();
                await controller.new();
                await controller.recommand();
                await controller.detail();
                controller.search();
                controller.about();
                controller.concat();
                controller.release();
                controller.help();
                break;
        }
    } catch (error) {
        console.log('[出错啦]', error);
    }
    console.log('well done.');
    process.exit(0);
})();